home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Day Cry
/
Day Cry CD.bin
/
oh_towns
/
taropyon
/
silib
/
silib.lzh
/
PRG
/
SDKFS
/
FSELREAD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-20
|
4KB
|
232 lines
/*************************************************************************
* âtâ@âCâïÅεò±é╠ô╟é▌ĵéΦ
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <silib.h>
#include <sifs.h>
#include "sdkfs.h"
#include "sdkfscf.h"
/*************************************************************************
* âtâ@âCâïÅεò±é╠Åëè·ë╗
*************************************************************************/
void FileSel_clearFndat( FILESEL_T *fs )
{
FNDAT_T *fndat, *next;
fndat = fs->fnTop;
while ( fndat )
{
next = fndat->next;
SI_FREE(fndat);
fndat = next;
}
fs->fnTop = NULL;
if ( fs->fnMat )
SI_FREE(fs->fnMat);
fs->fnMat = NULL;
fs->numFn = fs->numMat = fs->posDspTop = 0;
fs->posMark = -1;
}
static FNDAT_T *readdir(void)
{
int ret;
REG FNDAT_T *fndat;
static int opflg = FALSE;
static int no;
static struct find_t fbuf;
if ( opflg == FALSE ) /* Åëë±âRü[âï */
{
ret = _dos_findfirst( "*.*", 0x16, &fbuf);
opflg = TRUE;
no = 0;
} else
ret = _dos_findnext( &fbuf );
if ( ret ) /* error */
{
opflg = FALSE;
return (NULL);
}
if ( (fndat = SI_MALLOC(sizeof(FNDAT_T))) != NULL )
{
fndat->next = NULL;
fndat->no = no++;
fndat->flag = FALSE;
fndat->mark = FALSE;
fndat->buf = fbuf;
if ( !(fndat->buf.attrib & FSATT_DIR) )
FS_strlwr( fndat->buf.name ); /* żò╢ÄÜé╔ò╧è╖ */
}
return (fndat);
}
/*************************************************************************
* âfâBâîâNâgâèÅεò±é╠ô╟é▌ĵéΦ
*************************************************************************/
int FileSel_readdir( FILESEL_T *fs )
{
FNDAT_T *fndat;
FileSel_clearFndat( fs );
{
long totalFree, writeFree;
if ( FS_getDskFree( fs->drv, &totalFree, &writeFree) )
{
fs->err = FSERR_DRIVE;
return (ERR);
}
}
while ( (fndat = readdir()) != NULL )
{
++(fs->numFn);
if ( fs->fnTop )
{
fndat->next = fs->fnTop;
fs->fnTop = fndat;
} else
{
fndat->next = NULL;
fs->fnTop = fndat;
}
}
return (NORMAL);
}
static int wildMatch( CONST char *s )
{
char buf[256];
if ( strchr(s, '.') == NULL )
{ /* ègÆúÄqé═ÄwÆΦé│éΩé─éóé╚éó */
/* âsâèâIâhé╛é»Æ╟ë┴ */
sprintf(buf,"%s%c",s, '.');
return FS_wildMatch( buf );
} else
return FS_wildMatch( s );
}
/*************************************************************************
* âtâ@âCâïé╠æIæ≡üiâÅâïâCâhâJü[âhüj
*************************************************************************/
int FilsSel_pickup( FILESEL_T *fs )
{
int ai, argc;
char **argv;
char *wild;
if ( fs->numFn == 0 )
{
fs->err = FSERR_FILE;
return (ERR);
}
if ( fs->wild == NULL || (fs->wild && fs->wild[0] == '\0') )
wild = "*.*";
else
wild = fs->wild;
{
FNDAT_T *fndat;
fndat = fs->fnTop;
while ( fndat )
{
fndat->flag = FALSE;
fndat = fndat->next;
}
}
if ( fs->fnMat )
{
SI_FREE(fs->fnMat);
fs->fnMat = NULL;
}
fs->numMat = fs->posDspTop = 0;
if ( SI_argSet( &argc, &argv, wild) )
return (ERR);
for ( ai = 0; ai < argc; ++ai )
{
FNDAT_T *fndat;
FS_wildSet( argv[ai] );
fndat = fs->fnTop;
while ( fndat )
{
if( fndat->flag == FALSE )
{
if ( (fndat->buf.attrib & FSATT_DIR) || wildMatch( fndat->buf.name ) )
{
++(fs->numMat);
fndat->flag = TRUE;
}
}
fndat = fndat->next;
}
FS_wildFree();
}
SI_argFree( argc, argv );
if ( fs->numMat == 0 )
{
fs->err = FSERR_FILE;
return (ERR);
}
if ( fs->numMat > 0 )
{ /* â}âbâ`é╡é╜âtâ@âCâïÅεò±é╠É▌ÆΦ */
FNDAT_T *fndat;
int i = 0;
if ( (fs->fnMat = SI_MALLOC(sizeof(FNDAT_T *) * fs->numMat)) == NULL )
{
fs->numMat = 0;
fs->err = FSERR_MEMORY;
return (ERR);
}
fndat = fs->fnTop;
while ( fndat )
{
if ( fndat->flag )
fs->fnMat[i++] = fndat;
fndat = fndat->next;
}
}
return (NORMAL);
}
int FileSel_changedir( FILESEL_T *fs )
{
fs->posMark = -1;
fs->err = FSERR_NOERR;
FS_chdir2( fs->whare );
if ( FileSel_readdir( fs ) )
return (ERR);
if ( FilsSel_pickup( fs ) )
return (ERR);
FileSel_sort( fs );
return (NORMAL);
}